package com.xiaozhengkeji.blog.controller;


import com.xiaozhengkeji.blog.tools.CookieTool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;


@Controller
public class ViewController {
    Logger logger = LoggerFactory.getLogger(getClass());
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ModelAndView index(HttpServletRequest request, HashMap<String, Object> map) {
        ModelAndView modelAndView = new ModelAndView();
        Cookie[] cookie = request.getCookies();
        String eMail = CookieTool.getCookie("email", cookie);
        if (!(eMail.equalsIgnoreCase(""))) {
            modelAndView.addObject("email", eMail);
            modelAndView.addObject("email-url", "/admin/index.html");
        } else {
            modelAndView.addObject("email", "登陆");
            modelAndView.addObject("email-url", "/admin/login.html");
        }
        modelAndView.setViewName("index");
        return modelAndView;
    }



}